<!DOCTYPE html>
<#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
<html>
<head>
    <meta charset="utf-8">
    <title>组织管理/设置状态</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
    <form class="layui-form" action="" lay-filter="usersta-on">
    <div class="layui-tab layui-tab-card" style="height:315px ;margin: 0;">
        <ul class="layui-tab-title">
<!--            <li>角色选择</li>-->
            <li class="layui-this">用户状态</li>
        </ul>
        <div class="layui-tab-content">
<!--            <div class="layui-tab-item>-->
<!--                <div class="layui-container" style="padding:0">-->
<!--                    <div id="orgSeleter"></div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-tab-item layui-show">
                <div style="margin: 20px 60px 20px 30px">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否可用:</label>
                        <div class="layui-input-block">
                            <select name="isLock">
                                <option value="0">未锁定</option>
                                <option value="1">已锁定</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">当前状态:</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="0">禁用</option>
                                <option value="1">激活</option>
                                <option value="-1">删除</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否过期:</label>
                        <div class="layui-input-block">
                            <select name="isExpired">
                                <option value="0">未过期</option>
                                <option value="1">已过期</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户密级:</label>
                        <div class="layui-input-block">
                            <@secSelect.sec_select data_src=2 name="privacyLevel"/>
                            <!--<input type="text" name="privacyLevel" class="layui-input">-->
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
        <div style="text-align: center;margin: 15px 0">
            <a lay-submit lay-filter="formOffline" class="layui-btn btn-n" >保存</a>
            <a  class="layui-btn btn-n layui-btn-danger userCancelSta" >取消</a>
        </div>
    </form>
    <script src="${ctx}/public/component.js" type="text/javascript"></script>
    <script src="${ctx}/layui/layui.js"></script>
    <script>
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','transferSystem','form','setter','commons'], function () {
            var transfer = layui.transferSystem, form=layui.form, $ = layui.$,setter=layui.setter,commons=layui.commons;
            var userId = '${userId}';
            var queryByUserData=[];//查询当前用户角色
            var queryOrgRoleByUserData=[]; //获取当前组织下角色列表
            form.render();
            //表格列
            var cols = [{type: 'checkbox', fixed: 'left'},
                {field: 'roleId', title: 'ID', width: 80, sort: true, hide: true},
                {field: 'roleName', title: '角色名称'}];
            var colls = [{type: 'checkbox', fixed: 'left'},
                {field: 'roleId', title: 'ID', width: 80, sort: true, hide: true},
                {field: 'roleName', title: '角色名称'},
                {field: 'systemName', title: '子系统名称'}];
            //表格配置文件
            var tabConfig = {
                'height':260
            };

            $.ajax({ //获取数据 查询当前用户角色
                url: serverPath.systemPath + setter.sysLinkPath + "sysRole/queryOrgRoleByUserId",
                type: "get",
                contentType: 'application/json',
                dataType: 'json',
                async: false,
                data: {userId:userId},
                success: function (data) {
                    if (commons._filterRecord(data)) {
                        queryByUserData=data.data;
                    } else {
                       layer.alert(data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                },
            });
            $.ajax({ //获取当前组织下角色列表
                url: serverPath.systemPath + setter.sysLinkPath + "sysRole/queryByUserId",
                type: "get",
                contentType: 'application/json',
                dataType: 'json',
                async: false,
                data: {userId:userId},
                success: function (data) {
                    if (commons._filterRecord(data)) {
                        queryOrgRoleByUserData=data.data;
                    } else {
                        layer.alert(data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                },
            });
            var tb1 = transfer.render({
                elem: "#orgSeleter", //指定元素
                cols: cols, //表格列  左侧  支持layui数据表格所有配置
                colls: colls, //表格列 右侧 支持layui数据表格所有配置
                data: [queryByUserData, queryOrgRoleByUserData], //[左表数据,右表数据[非必填]]
                tabConfig: tabConfig //表格配置项 支持layui数据表格所有配置
            });

            $.ajax({  //用户状态回写
                url: serverPath.systemPath + setter.sysLinkPath + "sysUser/get",
                type: "get",
                contentType: 'application/json',
                dataType: 'json',
                data: {userId:userId},
                success: function (data) {
                    //表单初始赋值
                    var returnDate = data.data;
                    form.val('usersta-on', {
                        "isLock": returnDate.isLock,
                        "status": returnDate.status,
                        "isExpired": returnDate.isExpired,
                        "privacyLevel": returnDate.privacyLevel,
                        "isOnline": returnDate.isOnline
                    })
                    form.render("select");
                }
            });
               form.on('submit(formOffline)', function(data){
                   //获取数据
                   var datas = transfer.get(tb1, 'r');//角色选择数据  //transfer.get(参数1:初始化返回值,参数2:获取数据[all,left,right,l,r],参数:指定数据字段)
                   var  roleId=[];
                   $.each( datas, function(index, content) {
                       roleId.push(content.roleId)
                   });
                   data.field.userId = userId;
                   data.field.roleId = roleId;
                   $.ajax({
                       url: serverPath.systemPath + setter.sysLinkPath + "sysUser/setupState",
                       type: "POST",
                       contentType: 'application/json',
                       dataType: 'json',
                       data: JSON.stringify(data.field),
                       success: function (data) {
                           if (commons._filterRecord(data)) {
                               window.parent.layer.alert(data.msg, function (index) {
                                   parent.layer.close(index);
                                   parent.layui.table.reload('userListTable',{page:{curr:1}});
                                   parent.layui.totalFilter.init('userListTable');
                                   parent.window.Initialization();
                                   parent.layer.close(parent.layer.getFrameIndex(window.name));
                               });
                           } else {
                               window.parent.layer.alert(data.msg);
                           }
                       },
                       error: function (XMLHttpRequest, textStatus, errorThrown) {
                           layer.alert("保存失败！" + XMLHttpRequest.status);
                       },
                   });
                   return false;
               });
               $(".userCancelSta").click(function () {
                   parent.layer.close(parent.layer.getFrameIndex(window.name));
                   return false;
               })
        })
    </script>
    </body>
    </html>